package com.hutu.controller.biz.admin;

import com.aspect.ApiOperationLog;
import com.hutu.model.resp.Response;
import com.hutu.model.resp.ResponseVo;
import com.hutu.service.biz.ColumnService;
import com.hutu.model.biz.Column;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 字段信息 Controller
 * </p>
 *
 * @author admin
 * @since 2023-07-15
 */
@RestController
@RequestMapping("/admin/column")
@Api(tags = "字段信息")
public class ColumnController {
    @Resource
    private ColumnService columnService;

    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseVo add(@RequestBody Column column){
        return this.columnService.add(column);
    }

    @ApiOperation("逻辑删除")
    @DeleteMapping("/{id}")
    public ResponseVo delete(@PathVariable Integer id){
        return this.columnService.deleteById(id);
    }

    @ApiOperation("批量逻辑删除")
    @DeleteMapping("/batch/{ids}")
    public ResponseVo deleteBatch(@PathVariable List<Integer> ids){
        return this.columnService.deleteBatch(ids);
    }

    @ApiOperation("编辑更新")
    @PutMapping("/edit")
    public ResponseVo edit(@RequestBody Column column){
        return this.columnService.edit(column);
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    public ResponseVo findById(@PathVariable Integer id){
        return this.columnService.findById(id);
    }

    @ApiOperation("分页条件查询")
    @GetMapping
    @ApiOperationLog(description = "分页查询字段信息")
    public ResponseVo list(@RequestParam(defaultValue = "1") Integer current,@RequestParam(defaultValue = "10") Integer size,String name){
        return this.columnService.list(current,size,name);
    }

    @ApiOperation("数据导出接口")
    @GetMapping("/export")
    public ResponseVo export(HttpServletResponse response)throws IOException{
        return this.columnService.export(response);
    }

    @ApiOperation("数据导入接口")
    @PostMapping("/import")
    public ResponseVo imp(MultipartFile file)throws IOException{
        return this.columnService.imp(file);
    }

    @ApiOperation("查询")
    @GetMapping("/findByTableId/{id}")
    public ResponseVo findByTableId(@PathVariable Integer id){
        return Response.success(this.columnService.findByTableId(id));
    }
}

